import createDOMElement from './createDOMElement'
import unmountNode from './unmountNode'

export default function mountNativeElement (virtualDOM, container, oldDOM) {
  const newElement = createDOMElement(virtualDOM)
  // 转换之后将DOM对象放到页面中
  if (oldDOM) {
    container.insertBefore(newElement, oldDOM)
  } else {
    container.appendChild(newElement)
  }

  // 判断旧的dom对象是否存在，如果存在则删除
  oldDOM && unmountNode(oldDOM)

  let component = virtualDOM.component
  if (component) {
    component.setDOM(newElement)
  }
}